<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/template.xhtml">
	<ui:define name="title">
		SGMF :: Relatório de Notas Fiscais
	</ui:define>

	<ui:define name="content">
		<p:fieldset legend="Buscar Nota Fiscal">
			<h:form id="search">
				<p:panelGrid columns="7" styleClass="borderless">
					<p:outputLabel value="Data Início" for="inicio" />
					<p:calendar id="inicio" value="#{relatorioNotaFiscalBean.inicio}" />
					<p:outputLabel value="Data Fim" for="fim" />
					<p:calendar id="fim" value="#{relatorioNotaFiscalBean.fim}" />
					<p:commandButton id="buscar" value="Buscar"
						actionListener="#{relatorioNotaFiscalBean.buscar}"
						update=":result_form:result" icon="ui-icon-search" ajax="false" />
				</p:panelGrid>
			</h:form>
		</p:fieldset>
		<br />
		<h:form id="result_form">
			<p:commandButton id="gerarRelatorio" value="Gerar Relatório" process="@this" icon="ui-icon-note" rendered="#{not empty relatorioNotaFiscalBean.notasFiscais}" ajax="false">
				<p:dataExporter type="pdf" target="result" fileName="nota_fiscal" preProcessor="#{relatorioNotaFiscalBean.preProcessPDF}" />
			</p:commandButton>
			<br />
			<br />
			<p:dataTable id="result" var="notaFiscal"
			value="#{relatorioNotaFiscalBean.notasFiscais}" rows="10" paginator="true"
			paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} "
			currentPageReportTemplate="({currentPage} de {totalPages})"
			emptyMessage="Nenhum registro encontrado."
			rendered="#{relatorioNotaFiscalBean.notasFiscais != null}">
			<p:column headerText="Data">
				<h:outputText value="#{notaFiscal.dataEmissao}">
					<f:convertDateTime dateStyle="medium" />
				</h:outputText>
			</p:column>
			<p:column headerText="CNPJ">
				<h:outputText value="#{notaFiscal.fornecedor.cnpj}" />
			</p:column>
			<p:column headerText="Nome Fantasia">
				<h:outputText value="#{notaFiscal.fornecedor.nomeFantasia}" />
			</p:column>
			<p:column headerText="Razão Social">
				<h:outputText value="#{notaFiscal.fornecedor.razaoSocial}" />
			</p:column>
		</p:dataTable>
		</h:form>
	</ui:define>
</ui:composition>

</html>